home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 001-100 / 001-025 / 022 / lemacs / tcap.c < prev    next >
C/C++ Source or Header  |  1995-03-17  |  3KB  |  162 lines

  1. /*    tcap:    Unix V5, V7 and BS4.2 Termcap video driver
  2.         for MicroEMACS
  3. */
  4.  
  5. #define    termdef    1            /* don't define "term" external */
  6.  
  7. #include <stdio.h>
  8. #include    "estruct.h"
  9. #include        "edef.h"
  10.  
  11. #if TERMCAP
  12.  
  13. #define NROW    24
  14. #define NCOL    80
  15. #define    MARGIN    8
  16. #define    SCRSIZ    64
  17. #define BEL     0x07
  18. #define ESC     0x1B
  19.  
  20. extern int      ttopen();
  21. extern int      ttgetc();
  22. extern int      ttputc();
  23. extern int      ttflush();
  24. extern int      ttclose();
  25. extern int      tcapmove();
  26. extern int      tcapeeol();
  27. extern int      tcapeeop();
  28. extern int      tcapbeep();
  29. extern int    tcaprev();
  30. extern int      tcapopen();
  31. extern int      tput();
  32. extern char     *tgoto();
  33.  
  34. #define TCAPSLEN 315
  35. char tcapbuf[TCAPSLEN];
  36. char *UP, PC, *CM, *CE, *CL, *SO, *SE;
  37.  
  38. TERM term = {
  39.         NROW-1,
  40.         NCOL,
  41.     MARGIN,
  42.     SCRSIZ,
  43.         tcapopen,
  44.         ttclose,
  45.         ttgetc,
  46.         ttputc,
  47.         ttflush,
  48.         tcapmove,
  49.         tcapeeol,
  50.         tcapeeop,
  51.         tcapbeep,
  52.         tcaprev
  53. };
  54.  
  55. tcapopen()
  56.  
  57. {
  58.         char *getenv();
  59.         char *t, *p, *tgetstr();
  60.         char tcbuf[1024];
  61.         char *tv_stype;
  62.         char err_str[72];
  63.  
  64.         if ((tv_stype = getenv("TERM")) == NULL)
  65.         {
  66.                 puts("Environment variable TERM not defined!");
  67.                 exit(1);
  68.         }
  69.  
  70.         if((tgetent(tcbuf, tv_stype)) != 1)
  71.         {
  72.                 sprintf(err_str, "Unknown terminal type %s!", tv_stype);
  73.                 puts(err_str);
  74.                 exit(1);
  75.         }
  76.  
  77.         p = tcapbuf;
  78.         t = tgetstr("pc", &p);
  79.         if(t)
  80.                 PC = *t;
  81.  
  82.         CL = tgetstr("cl", &p);
  83.         CM = tgetstr("cm", &p);
  84.         CE = tgetstr("ce", &p);
  85.         UP = tgetstr("up", &p);
  86.     SE = tgetstr("se", &p);
  87.     SO = tgetstr("so", &p);
  88.     if (SO != NULL)
  89.         revexist = TRUE;
  90.  
  91.         if(CL == NULL || CM == NULL || UP == NULL)
  92.         {
  93.                 puts("Incomplete termcap entry\n");
  94.                 exit(1);
  95.         }
  96.  
  97.     if (CE == NULL)        /* will we be able to use clear to EOL? */
  98.         eolexist = FALSE;
  99.         
  100.         if (p >= &tcapbuf[TCAPSLEN])
  101.         {
  102.                 puts("Terminal description too big!\n");
  103.                 exit(1);
  104.         }
  105.         ttopen();
  106. }
  107.  
  108. tcapmove(row, col)
  109. register int row, col;
  110. {
  111.         putpad(tgoto(CM, col, row));
  112. }
  113.  
  114. tcapeeol()
  115. {
  116.         putpad(CE);
  117. }
  118.  
  119. tcapeeop()
  120. {
  121.         putpad(CL);
  122. }
  123.  
  124. tcaprev(state)        /* change reverse video status */
  125.  
  126. int state;    /* FALSE = normal video, TRUE = reverse video */
  127.  
  128. {
  129.     if (state) {
  130.         if (SO != NULL)
  131.             putpad(SO);
  132.     } else {
  133.         if (SE != NULL)
  134.             putpad(SE);
  135.     }
  136. }
  137.  
  138. tcapbeep()
  139. {
  140.         ttputc(BEL);
  141. }
  142.  
  143. putpad(str)
  144. char    *str;
  145. {
  146.         tputs(str, 1, ttputc);
  147. }
  148.  
  149. putnpad(str, n)
  150. char    *str;
  151. {
  152.         tputs(str, n, ttputc);
  153. }
  154.  
  155. #else
  156.  
  157. hello()
  158. {
  159. }
  160.  
  161. #endif TERMCAP
  162.